/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.worlds.ui.edge;

import java.awt.Color;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.worlds.Main;
import net.worlds.Util;

/**
 *
 * @author Jacob
 */
public class SiteChat {
    private static final int MAX_CHATS = 64;
    private static List<ChatMessage> chats = Collections.synchronizedList(new ArrayList<ChatMessage>(MAX_CHATS));
    public static class ChatMessage {
        public Color color;
        public String message;
        public ChatMessage(Color color, String message)
        {
            this.color = color;
            this.message = message;
        }
    }
    public static void addChat(Color color, String message)
    {
        synchronized(chats)
        {
            if(chats.size() == MAX_CHATS)
                chats.remove(chats.size() - 1);
            chats.add(0, new ChatMessage(color, message));
        }
    }
    public static List<ChatMessage> getChats()
    {
        return chats;
    }
    public static void send(String text)
    {
        try {
            String url = "http://"+Main.siteURL+"/frames/sendChat.php?uid="+Main.getLoginID()+"&key="+Main.getLoginKey()+"&msg="+URLEncoder.encode(text, "UTF-8");
            Util.httpGet(url);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
}
